package model23;

/**
 * @Author ilongsay
 * @Date: Create in 2019/10/13 19:58
 * @Description: don't bb,show you code
 */
public class Singleton {

    private Singleton() {}

    /**
     * 内部类的实现
     */
    private static class InnerSingleton {
        private static Singleton singleton = new Singleton();
    }

    public static Singleton getInstance() {
        return InnerSingleton.singleton;
    }

    private User user() {
        return new User();
    }

    public static void main(String[] args) {
        Singleton instance = Singleton.getInstance();
        Singleton instance1 = Singleton.getInstance();
        System.out.println(instance == instance1);
        System.out.println("==================");
        System.out.println(instance.user()==instance1.user());
    }
}
